using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Wrath.Windows.Forms;

namespace Wrath.RuleForge.Imaging
{
    public partial class ImageViewer : DockContent
    {
        private string path;
        private string filename;

        public ImageViewer()
        {
            InitializeComponent();
        }

        public ImageViewer(string imagePath)
        {
            InitializeComponent();

            path = imagePath;
        }

        private void ImageViewer_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(path))
            {
                SetPicture(path);
            }
        }

        public void SetPicture(string imagePath)
        {
            path = imagePath;

            filename = path.Substring(path.LastIndexOf('\\') + 1);
            this.TabText = filename;

            pictureBox.Load(path);
            
            // Center Picture.
            int picLeft = this.Width - pictureBox.Width;
            if (picLeft > 0)
            {
                pictureBox.Left = (this.Width / 2) - (pictureBox.Width / 2);
            }
            else
            {
                pictureBox.Left = 1;
            }

            int picTop = this.Height - pictureBox.Height;
            if (picTop > 0)
            {
                pictureBox.Top = (this.Height / 2) - (pictureBox.Height / 2);
            }
            else
            {
                pictureBox.Top = 1;
            }
        }
    }
}